from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, pipeline

# 定义模型名称
model_name = 'liam168/trans-opus-mt-zh-en'

# 加载模型和分词器
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)

# 创建翻译管道
pipe = pipeline("translation_zh_to_en", model=model, tokenizer=tokenizer)

# 输入要翻译的中文句子
text_to_translate = '我喜欢学习数据科学和机器学习。'

# 执行翻译
result = pipe(text_to_translate, max_length=400)

# 输出翻译结果
print("result :", result)
print("text   :", result[0]['translation_text'])
